<script>
import { RouterLink, RouterView } from 'vue-router'
import {mapState,mapGetters,mapMutations} from 'vuex'
import axios from 'axios'
export default {
  data(){
    return{

    };
  },
  mounted(){
    this.getShopList()
  },
  methods:{
    ...mapMutations('user',['updateShop','updateUser']),
    
    getShopList(){
      axios.get("/api/public/v1/shop/to_seller",{
        params: {
          seller_id:this.user.id
        }
      })
      .then(res => {
        if(res.data.meta.status==200){
          this.updateShop(res.data.message)
        }
        else{
          alert(res.data.message)
        }
      })
      .catch(err => {
        console.error(err); 
      })
    },
    quit(){
      this.updateUser({})
      this.updateShop([])
      window.location.replace("http://localhost:5173");
    }
    
  },
  computed:{
    ...mapState('user',['user'])
  }
}
</script>
<template>
  <el-container class="container">
    <el-header class="header">
      <h1>茶途</h1>
      <div class="user-name">
        <el-menu>
          <el-sub-menu index="10">
            <template v-slot:title>
              <el-icon><UserFilled /></el-icon>
              {{this.user.seller_name}}
            </template>
            <el-menu-item>
              <p @click="quit">退出</p>
            </el-menu-item>
          </el-sub-menu>
        </el-menu>
      </div>
      
    </el-header>
    <el-container class="body">
      <el-aside class="aside">
        <el-menu>
          <el-menu-item>
            <el-icon><Shop /></el-icon>
            店铺
          </el-menu-item>
          <el-sub-menu index="1">
            <template v-slot:title>
              <el-icon><GoodsFilled /></el-icon>
              商品
            </template>
            <el-menu-item>
              <RouterLink :to="{name:'goods'}">浏览商品</RouterLink>
            </el-menu-item>
            <el-menu-item>
                设置
            </el-menu-item>
          </el-sub-menu>
          <el-sub-menu index="2">
            <template #title>
              <el-icon><Tickets /></el-icon>
              订单
            </template>
            <el-menu-item>
              待处理
            </el-menu-item>
            <el-menu-item>
              运输中
            </el-menu-item>
            <el-menu-item>
              待确认
            </el-menu-item>
            <el-menu-item>
              历史订单
            </el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-aside>
      <el-main class="main">
        <RouterView></RouterView>
      </el-main>
    </el-container>
  </el-container>
</template>

<style>
*{
  margin: 0;
  padding: 0;
}
.container{
  background-color: white;
  .header{
    background-color: white;
    h1{
      color: #008000;
      font-size: 40px;
    }
    display: flex;
    justify-content: space-between;
    border-bottom: #efefef 1px solid;
    height: 15%;
    .user-name{
      color: black;
    }
    .user-name:hover{
      cursor: pointer;
    }
  }
  .body{
    .aside{
      background-color: white;
    }
    .main{
      background-color: white;
    }
  }
}
</style>
